package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class POSTable extends AbstractData {
	private long id = -1;
	private transient long hotelId;
	private String tableTitle;
	private POSZone zone;
	private String zoneString;
	private boolean status;
	private boolean avaliable;

	public POSTable() {
		status = true;
		avaliable = true;
	}

	public POSTable(long id) {
		this.id = id;
		this.status = true;
		this.avaliable = true;
	}

	public long getId() {
		return id;
	}

	public long getHotelId() {
		return hotelId;
	}

	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}

	public void setId(long id) {
		this.id = id;
	}
	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public boolean isAvaliable() {
		return avaliable;
	}

	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}
	
	public String getTableTitle() {
		return tableTitle;
	}

	public void setTableTitle(String tableTitle) {
		this.tableTitle = tableTitle;
	}

	public String getZoneString() {
		return zoneString;
	}

	public void setZoneString(String zoneString) {
		this.zoneString = zoneString;
	}
	
	public POSZone getZone() {
		if (zone == null && !(zoneString == null || zoneString.isEmpty())) {
			POSZone b = new POSZone(Long.parseLong(zoneString));
			b.LoadData();
			zone = b;
		}
		return zone;
	}

	public void setZone(POSZone zone) {
		this.zoneString = String.format("%d", zone.getId());
		this.zone = zone;
	}

	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.POSTable);
		else
			item = new Entity(this.key);
		item.setProperty("tableTitle", this.tableTitle);
		item.setProperty("zone", this.zoneString);
		item.setProperty("hotelId", this.hotelId);
		item.setProperty("status", this.status);
		item.setProperty("avaliable", this.avaliable);
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.tableTitle=(String)entity.getProperty("tableTitle");
		this.zoneString=(String)entity.getProperty("zone");
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.avaliable = (Boolean) entity.getProperty("avaliable");
		this.status = (Boolean) entity.getProperty("status");
		this.key = entity.getKey();
	}

	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.POSTable, this.id);
			setEntity(entity);
		}
	}

}
